# -*- coding:utf-8 -*-

# 定义一个蓝图用来访问静态页面
from flask import Blueprint

# 创建蓝图，定义一个名字和模块
from flask import current_app
from flask import make_response
from flask.ext.wtf.csrf import generate_csrf

html = Blueprint("html",__name__)

# http://127.0.0.1:5000/favicon.ico,所有的路由器请求图标的都是这个命令
# 用蓝图注册路由
@html.route("/<re('.*'):file_name>")
def get_html_file(file_name):

    if not file_name:

        file_name = "index.html"

    if file_name != "favicon.ico":
        file_name = "html/"+ file_name

    # # 调用send_static_file方法，组织号路径
    #
    # return  current_app.send_static_file(file_name)

     # send_static_file：通过指定的文件名找到指定的静态文件并封装成响应
    response = make_response(current_app.send_static_file(file_name))
    # 生成csrf_token的值
    csrf_token = generate_csrf()

    # 设置csrftoken的cookie
    response.set_cookie("csrf_token", csrf_token)
    return response



